package com.lc.dubbo.consumer;

import com.lc.api.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.qos.common.QosConstants;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author liuc
 * @date 2021/6/17
 * @description
 **/
public class ConsumerApp {

    private static ExecutorService executorService = Executors.newFixedThreadPool(6);

    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConf.class);
        context.start();
        DubboConsumer consumer = (DubboConsumer)context.getBean("dubboConsumer");
        executorService.execute(() -> {
            int j = 2000;
            while(j>0){
                consumer.testA();
                j--;
            }
            System.out.println("methodA invoke finish!");
        });
        executorService.execute(() -> {
            int j = 2000;
            while(j>0){
                consumer.testA();
                j--;
            }
            System.out.println("methodA invoke finish!");
        });
        executorService.execute(() -> {
            int j = 2000;
            while(j>0){
                consumer.testB();
                j--;
            }
            System.out.println("methodB invoke finish!");
        });
        executorService.execute(() -> {
            int j = 2000;
            while(j>0){
                consumer.testB();
                j--;
            }
            System.out.println("methodB invoke finish!");
        });
        executorService.execute(() -> {
            int j = 2000;
            while(j>0){
                consumer.testC();
                j--;
            }
            System.out.println("methodC invoke finish!");
        });
        executorService.execute(() -> {
            int j = 2000;
            while(j>0){
                consumer.testC();
                j--;
            }
            System.out.println("methodC invoke finish!");
        });
        System.out.println("############### invoke finished #################");
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "com.lc.dubbo.consumer")
    @PropertySource("classpath:dubbo-consumer.properties")
    @ComponentScan("com.lc.dubbo.consumer")
    static class ConsumerConf{
    }

}
